#!/usr/bin/env bash

ROOT=~/data/YLIMED/mp4_short_encode
TrainSplit=$ROOT/YLIMED_short_mp4_EvAll_split_train.txt
TestSplit=$ROOT/YLIMED_short_mp4_EvAll_split_test.txt
DEVTrainSplit=$ROOT/YLIMED_short_mp4_EvAll_split_train_dev.txt
DEVTestSplit=$ROOT/YLIMED_short_mp4_EvAll_split_test_dev.txt
ValSplit=$ROOT/YLIMED_short_mp4_EvAll_split_val.txt

TOYSplit=$ROOT/YLIMED_short_mp4_EvAll_split_test_toy.txt
OUT=out/ylimed_finetuning02/log

if [ $1 == "dev" ]
then
    echo "develop"

    # YLIMED model.
    python train.py --lr 0.0003 --batch-size 4 --arch resnet152 \
        --data-name ylimed --representation iframe \
        --data-root  $ROOT \
        --train-list $TOYSplit \
        --test-list  $TOYSplit \
        --model-prefix ylimed_toyyyyy \
        --lr-steps 40 80 100  --epochs 120 \
        --gpus 0 1

    wait
    exit

    # # I-frame model.
    # python train.py --lr 0.0003 --batch-size 32 --arch resnet152 \
    #     --data-name hmdb51 --representation iframe \
    #     --data-root data/hmdb51/mpeg4_videos \
    #     --train-list data/datalists/hmdb51_split2_train.txt \
    #     --test-list data/datalists/hmdb51_split2_test.txt \
    #     --model-prefix hmdb51_iframe3_model_deeeeeeeev \
    #     --lr-steps 55 110 165  --epochs 220 \
    #     --gpus 0 1
    # exit
    # python train.py --lr 0.005 --batch-size 60 --arch resnet18 \
    #     --data-name hmdb51 --representation mv \
    #     --data-root data/hmdb51/mpeg4_videos \
    #     --train-list data/datalists/hmdb51_split2_train.txt \
    #     --test-list data/datalists/hmdb51_split2_test.txt \
    #     --model-prefix hmdb51_mv2_model_tesssssssssssst \
    #     --lr-steps 120 200 280  --epochs 360 \
    #     --workers 1 \
    #     --gpus 0
    # exit
    # wait

elif [ $1 == "ylimed" ]
then
    # 判断目录是不是已经存在，如果不存在则创建，存在则输出“dir exist”
    dirname=$OUT
    # echo "the dir name is $dirname"
    if [ ! -d $dirname  ];then
        mkdir $dirname
    else
        echo dir exist
    fi

    # -n 选项
    echo "ylimed iframe start: $(date "+%Y-%m-%d %H:%M:%S")"
    set -x
    python train.py --lr 0.0003 --batch-size 32 --arch resnet152 \
        --data-name ylimed --representation iframe \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $ValSplit \
        --model-prefix ylimed \
        --lr-steps 40 80 100  --epochs 120 \
        --eval-freq 1 \
        --weight-decay 0.001 \
        --gpus 0 1 > $OUT/ylimed_iframe_model.out 2>&1
    set +x
    wait
    echo "ylimed iframe end: $(date "+%Y-%m-%d %H:%M:%S")"

    echo "ylimed mv start: $(date "+%Y-%m-%d %H:%M:%S")"
    set -x
    python train.py --lr 0.005 --batch-size 96 --arch resnet18 \
        --data-name ylimed --representation mv \
        --data-root $ROOT \
        --train-list $TrainSplit \
        --test-list $ValSplit \
        --model-prefix ylimed \
        --lr-steps 80 150 200  --epochs 230 \
        --eval-freq 1 \
        --weight-decay 0.001 \
        --gpus 0 > $OUT/ylimed_mv_model.out 2>&1
    set +x
    wait
    echo "ylimed mv end: $(date "+%Y-%m-%d %H:%M:%S")"

    echo "ylimed residual start: $(date "+%Y-%m-%d %H:%M:%S")"
    set -x
    python train.py --lr 0.001 --batch-size 96 --arch resnet18 \
        --data-name ylimed --representation residual \
        --data-root $ROOT \
        --train-list $TrainSplit \
        --test-list $ValSplit \
        --model-prefix ylimed \
        --lr-steps 80 120 180  --epochs 200 \
        --eval-freq 1 \
        --weight-decay 0.001 \
        --gpus 0 > $OUT/ylimed_residual_model.out 2>&1
    set +x
    wait
    echo "ylimed residual end: $(date "+%Y-%m-%d %H:%M:%S")"

elif [ $1 == "redo" ]
then
    # I-frame model.
    python train.py --lr 0.0003 --batch-size 32 --arch resnet152 \
        --data-name hmdb51 --representation iframe \
        --data-root data/hmdb51/mpeg4_videos \
        --train-list data/datalists/hmdb51_split3_train.txt \
        --test-list data/datalists/hmdb51_split3_test.txt \
        --model-prefix hmdb51_iframe3_model \
        --lr-steps 55 110 165  --epochs 220 \
        --gpus 0 1 > hmdb51_iframe3_model.out 2>&1
    wait

    # Motion vector model.
    python train.py --lr 0.005 --batch-size 80 --arch resnet18 \
        --data-name hmdb51 --representation mv \
        --data-root data/hmdb51/mpeg4_videos \
        --train-list data/datalists/hmdb51_split3_train.txt \
        --test-list data/datalists/hmdb51_split3_test.txt \
        --model-prefix hmdb51_mv3_model \
        --lr-steps 120 200 280  --epochs 360 \
        --gpus 0 > hmdb51_mv3_model.out 2>&1

    wait

    # Residual model.
    python train.py --lr 0.001 --batch-size 80 --arch resnet18 \
        --data-name hmdb51 --representation residual \
        --data-root data/hmdb51/mpeg4_videos \
        --train-list data/datalists/hmdb51_split3_train.txt \
        --test-list data/datalists/hmdb51_split3_test.txt \
        --model-prefix hmdb51_residual3_model \
        --lr-steps 120 180 240  --epochs 300 \
        --gpus 0 > hmdb51_residual3_model.out 2>&1

    wait

    # I-frame model.
    python train.py --lr 0.0003 --batch-size 64 --arch resnet152 \
        --data-name ucf101 --representation iframe \
        --data-root data/ucf101/mpeg4_videos \
        --train-list data/datalists/ucf101_split3_train.txt \
        --test-list data/datalists/ucf101_split3_test.txt \
        --model-prefix ucf101_iframe3_model \
        --lr-steps 150 270 390  --epochs 510 \
        --gpus 0 1 2 3 > ucf101_iframe3_model.out 2>&1
    wait

    # Motion vector model.
    python train.py --lr 0.01 --batch-size 80 --arch resnet18 \
        --data-name ucf101 --representation mv \
        --data-root data/ucf101/mpeg4_videos \
        --train-list data/datalists/ucf101_split3_train.txt \
        --test-list data/datalists/ucf101_split3_test.txt \
        --model-prefix ucf101_mv3_model \
        --lr-steps 150 270 390  --epochs 510 \
        --gpus 0 > ucf101_mv3_model.out 2>&1
    wait

    # Residual model.
    python train.py --lr 0.005 --batch-size 80 --arch resnet18 \
        --data-name ucf101 --representation residual \
        --data-root data/ucf101/mpeg4_videos \
        --train-list data/datalists/ucf101_split3_train.txt \
        --test-list data/datalists/ucf101_split3_test.txt \
        --model-prefix ucf101_residual3_model \
        --lr-steps 150 270 390  --epochs 510 \
        --gpus 0 > ucf101_residual3_model.out 2>&1

    wait
else
    echo "Please make sure the positon variable is dev/ylimed/real."
fi
